//
//  CustomAlert.m
//  CustomAlert
//
//  Created by Elean on 16/5/25.
//  Copyright © 2016年 Elean. All rights reserved.
//

#import "CustomAlert.h"

@implementation CustomAlert

+ (void)showAlertWithController:(UIViewController *)ctr andTitle:(NSString *)title andMessage:(NSString *)message andTime:(NSTimeInterval)time{
    
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    [ctr presentViewController:alert animated:YES completion:nil];
    
    
    
    
    //延迟触发aler dismiss
    
    [self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:time];

    //延迟time 触发事件 事件有一个参数 alert

}

+ (void)dismissAlert:(UIAlertController *)alert{

    [alert dismissViewControllerAnimated:YES completion:nil];
    
}

+ (void)showAlertWithController:(UIViewController *)ctr andTitle:(NSString *)title andMessage:(NSString *)message andTime:(NSTimeInterval)time andBlock:(void (^)(void))blcok{

    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    [ctr presentViewController:alert animated:YES completion:nil];
    
    NSDictionary *dic = @{@"alert":alert , @"block":blcok};
    
    
    [self performSelector:@selector(dismissAlertWithDic:) withObject:dic afterDelay:time];
    
    
}

+ (void)dismissAlertWithDic:(NSDictionary *)dic{

    UIAlertController *alert = dic[@"alert"];
    
    [alert dismissViewControllerAnimated:YES completion:nil];
    
    void (^block)(void) = dic[@"block"];
    
    block();
    
    
}


@end




